package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FamFamily;
import com.ruoyi.system.service.IFamFamilyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家谱Controller
 * 
 * @author wk
 * @date 2022-05-07
 */
@RestController
@RequestMapping("/system/family")
public class FamFamilyController extends BaseController
{
    @Autowired
    private IFamFamilyService famFamilyService;

    /**
     * 查询家谱列表
     */
    @PreAuthorize("@ss.hasPermi('system:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamFamily famFamily)
    {
        startPage();
        List<FamFamily> list = famFamilyService.selectFamFamilyList(famFamily);
        return getDataTable(list);
    }

    /**
     * 导出家谱列表
     */
    @PreAuthorize("@ss.hasPermi('system:family:export')")
    @Log(title = "家谱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamFamily famFamily)
    {
        List<FamFamily> list = famFamilyService.selectFamFamilyList(famFamily);
        ExcelUtil<FamFamily> util = new ExcelUtil<FamFamily>(FamFamily.class);
        util.exportExcel(response, list, "家谱数据");
    }

    /**
     * 获取家谱详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:family:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(famFamilyService.selectFamFamilyById(id));
    }

    /**
     * 新增家谱
     */
    @PreAuthorize("@ss.hasPermi('system:family:add')")
    @Log(title = "家谱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamFamily famFamily)
    {
        famFamily.setCreateBy(getUsername());
        return toAjax(famFamilyService.insertFamFamily(famFamily));
    }

    /**
     * 修改家谱
     */
    @PreAuthorize("@ss.hasPermi('system:family:edit')")
    @Log(title = "家谱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamFamily famFamily)
    {
        return toAjax(famFamilyService.updateFamFamily(famFamily));
    }

    /**
     * 删除家谱
     */
    @PreAuthorize("@ss.hasPermi('system:family:remove')")
    @Log(title = "家谱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(famFamilyService.deleteFamFamilyByIds(ids));
    }

}
